﻿
@{
    ViewBag.Title = "ViewPlanDetail";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script type="text/javascript">
    var keyValue = $.request("keyValue");
    var f = $.request("from");
    var zt = $.request("zxzt");
    $(function () {
        if (!!keyValue) {
            gridList();
        }
    });
    //明细
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/HospitalizationManage/BookkeepInHos/AccountingPlanDetailQuery",
            height: $(window).height() - 120,
            postData: { jzjhmxId: keyValue, from: f },
            colModel: [
            { label: "zxId", name: "zxId", align: "left", hidden: true, key: true },
            { label: "jzjhmxId", name: "jzjhmxId", width: 100, align: "left", hidden: true },
            { label: "患者姓名", name: "xm", width: 70, align: "left" },
            { label: "病历号", name: "blh", hidden: true, align: "left" },
            { label: (f == "mz" ? "门诊号" : "住院号"), name: "mzzyh", width: (f == "mz" ? 100 : 70), align: "left", hidden: true },

            { label: "康复类别", name: "kflb", width: 80, align: "left" },
            { label: "治疗师", name: "zls", width: 80, align: "left" },
            { label: "收费项目", name: "sfxmmc", width: 120, align: "left" },
            { label: "治疗量", name: "zll", width: 80, align: "left" },
            { label: "单位", name: "dw", width: 40, align: "left" },
            { label: "数量", name: "sl", width: 40, align: "left" },
            {
                label: "报销政策", name: "zfxz", width: 60, align: "left",
                formatter: function (cellvalue) {
                    return $.enum.getDescByValue("EnumZiFuXingZhi", cellvalue);
                }
            },
            { label: "金额", name: "je", width: 55, align: "left", formatter: "number", formatoptions: { decimalPlaces: 2, defaultValue: '0.00' } },
            {
                label: "治疗日期", name: "zlrq", width: 80, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            },
            {
                label: "操作时间", name: "CreateTime", width: 140, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
            },
			{
			    label: "状态", name: "zt", width: 50, align: "left",
			    formatter: function (cellvalue, a, b) {
			        if (cellvalue == '1') {
			            return "正常"
			        }
			        else {
			            return "已撤销";
			        }
			    }
			}],
            pager: "#gridPager",
            rowNum: '15',
            sortname: 'CreateTime desc',
            viewrecords: true,
            gridComplete: function () {
                var ids = $("#gridList").getDataIDs();
                for (i = 0; i < ids.length; i++) {
                    var rowData = $("#gridList").getRowData(ids[i]);
                    if (rowData && rowData.zt) {
                        if (rowData.zt == "已撤销") {
                            $("#" + ids[i]).find("td").addClass('danger');
                        }
                    }
                }
            },
            ondblClickRow: function (rowid) {
                updateExc();
            }
        });
    }

    function cancelExc() {
        //181015已完成可以撤
        //if (zt == "已完成") {
        //    $.modalAlert("已完成计划无法撤销", 'warning');
        //    return;
        //}

        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var data = $("#gridList").jqGridRowValue();
        if (data.zt == "无效") {
            $.modalAlert("请选中一条有效信息", 'warning');
            return;
        }
        if (data) {
            $.najax({
                type: "GET",
                url: "/HospitalizationManage/BookkeepInHos/cancelExce?zxbh=" + data.zxId + "&jzjhmxId=" + data.jzjhmxId + "&from=" + f,
                loading: true,
                success: function (ajaxresp) {
                    $("#gridList").resetSelection();
                    $("#gridList").clearGridData();
                    $("#gridList").trigger("reloadGrid");
                }
            });
        }
    }

    function updateExc() {
        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var data = $("#gridList").jqGridRowValue();
        if (data.zt == "无效") {
            $.modalAlert("请选中一条有效信息", 'warning');
            return;
        }

        $.modalOpen({
            id: "UpdateExecForm",
            title: "更改执行详情",
            url: "/HospitalizationManage/BookkeepInHos/UpdateExecForm?keyValue=" + data.zxId + "&from=" + f,
            width: "500px",
            height: "300px",
            callBack: function (iframeId) {
                top.UpdateExecForm.submitForm(function () {
                    $("#gridList").resetSelection();
                    $("#gridList").clearGridData();
                    $("#gridList").jqGrid('setGridParam',
                    {
                        postData: { jzjhmxId: keyValue, from: f },
                        url: "/HospitalizationManage/BookkeepInHos/AccountingPlanDetailQuery"
                    }).trigger('reloadGrid');
                });

            }
        });
    }
</script>
<form name="form1">
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <input type="button" onclick="updateExc()" class="btn btn-primary btn-md" value="修改" style="float: right;margin-top: 10px;margin-right: 20px;" />
    <input type="button" id="cancelExce" onclick="cancelExc()" class="btn btn-primary btn-md" value="撤销执行" style="float: right;margin-top: 10px;margin-right: 20px;" />
</form>
